package com.shqcjd.yunweiyanoperator.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.shqcjd.yunweiyanoperator.R;
import com.shqcjd.yunweiyanoperator.ui.activity.staff.MainActivity;
import com.shqcjd.yunweiyanoperator.ui.base.BaseActivity;
import com.shqcjd.yunweiyanoperator.ui.base.BasePresenter;
import com.shqcjd.yunweiyanoperator.util.PrefUtils;

public class LauncherActivity extends BaseActivity {
    private final int TIMER = 1000;
    private final int FRE = 3;
    private int current = 0;
    private Context context;
    private Handler handler = new Handler();
    private Runnable runnable = new Runnable() {
        @Override
        public void run() {
            current++;
            if(current>=FRE){
                handler.removeCallbacks(runnable);
                if(PrefUtils.getInt(context, PrefUtils.USER_ID, -1)==-1){
                    startActivity(new Intent(context,LoginActivity.class));
                }else{
                    startActivity(new Intent(context, MainActivity.class));
//                    if(PrefUtils.getInt(context, PrefUtils.USER_TYPE, -1)==1){
//                        //管理员用户界面
//                        startActivity(new Intent(context,AdministerMainActivity.class));
//                    }else if(PrefUtils.getInt(context, PrefUtils.USER_TYPE, -1)==2){
//                        //普通员工界面
//                        startActivity(new Intent(context, MainActivity.class));
//                    }
                }
                finish();
            }else{
                handler.postDelayed(runnable, TIMER);
            }
        }
    };

    @Override
    public void init() {
        super.init();
        context = this;
    }

    @Override
    public void initView() {
        super.initView();
        handler.postDelayed(runnable, TIMER);
    }

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_launcher;
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(handler!=null){
            handler.removeCallbacks(runnable);
        }
    }

}
